app.service('shopBindUserService',['$q','utilService',function($q,utilService){
    var _this_=this;

    //根据手机号码查询用户
    _this_.findByMobilePhone= function ($scope) {
        var deferred = $q.defer();
        utilService.get({
            url:$scope.app.domain + 'user/phone/'+$scope.phone
        }).then(function(response){
            deferred.resolve(response.data);
        },function(e){
            console.error(e);
            deferred.reject("发生未知错误！请联系管理员");
        })

        return deferred.promise;
    }

    //发送用户绑定验证码
    _this_.sendUserBindCode= function ($scope,id) {
        var deferred = $q.defer();
        utilService.get({
            url:$scope.app.domain + 'user/code/'+id
        }).then(function(response){
            deferred.resolve(response.data);
        },function(e){
            console.error(e);
            deferred.reject("发生未知错误！请联系管理员");
        })

        return deferred.promise;
    }

    //发送解绑用户验证码
    _this_.sendUserUnBindCode= function ($scope,id) {
        var deferred = $q.defer();
        utilService.get({
            url:$scope.app.domain + 'user/code/'+id
        }).then(function(response){
            deferred.resolve(response.data);
        },function(e){
            console.error(e);
            deferred.reject("发生未知错误！请联系管理员");
        })
        return deferred.promise;
    }

    //绑定用户
    _this_.shopBindUser= function ($scope) {
        var deferred = $q.defer();
        utilService.api({
            url:$scope.app.domain + 'user/bind/'+$scope.id,
            data:{code:$scope.code},
            method:'PUT'
        }).then(function(result){
            deferred.resolve(result);
        });

        return deferred.promise;
    }


    _this_.shopUnBindUser=function($scope){
        var deferred = $q.defer();
        utilService.api({
            url:$scope.app.domain + 'user/unbound/'+$scope.id,
            data:{code:$scope.code},
            method:'PUT'
        }).then(function(result){
            deferred.resolve(result);
        });

        return deferred.promise;
    }


    _this_.getShopBindUser=function($scope){
        var deferred = $q.defer();
        utilService.get({
            url:$scope.app.domain +'user/shop'
        }).then(function(response){
            deferred.resolve(response.data);
        },function(e){
            console.error(e);
            deferred.reject("发生未知错误！请联系管理员");
        })
        return deferred.promise;
    }

}])